#include <set>
#include "httpprot_defs.h"
#include "httpprot_write.h"
#include "httpprot_headers.h"


namespace httpprot
{
	void Headers::WriteToBuffer( std::vector< char >& bufferOut ) const
	{
		for( std::vector< Header >::const_iterator end = m_headers.end( ),
			 it = m_headers.begin( ); it != end; ++it )
		{
			// Header = Name: SP Value CRLF
			WriteString( (*it).key, bufferOut );
			WriteChar( CLN, bufferOut );
			WriteChar( SP, bufferOut );
			WriteString( (*it).value, bufferOut );
			WriteChar( CR, bufferOut );
			WriteChar( LF, bufferOut );
		}
	}

	std::vector< Headers::Header >::iterator Headers::findHeaderWithKey( const std::string& key )
	{
		for( std::vector< Header >::reverse_iterator end = m_headers.rend( ),
			 it = m_headers.rbegin( ); it != end; ++it )
		{
			if( (*it).key == key )
				return it.base( );
		}

		return m_headers.end( );
	}
};